package com.library.praise.dao;

import com.framework.BaseDao;
import com.library.entity.Book;
import com.library.entity.Evaluate;
import com.library.entity.Praise;
import com.library.entity.Staff;
import org.springframework.stereotype.Repository;

import java.util.List;

@Repository
public class PraiseDaoImpl extends BaseDao<Praise,String> {

	public List<Praise> findByStaff(Staff staff){
		try{
			return super.findByProperty("from Praise p where p.staff=?", new Object[]{staff});
		}catch(Exception e){
			e.printStackTrace();
			return null;
		}
	}

	public List<Praise> findByEvaluate(Evaluate evaluate){
		try{
			return super.findByProperty("from Praise p where p.evaluate=?", new Object[]{evaluate});
		}catch(Exception e){
			e.printStackTrace();
			return null;
		}
	}

	public Praise findByStaffAndEvaluate(Staff staff,Evaluate evaluate){
		try{
			return super.findOne("from Praise p where p.staff=? and p.evaluate=?", new Object[]{staff,evaluate});
		}catch(Exception e){
			e.printStackTrace();
			return null;
		}
	}

	public List<Praise> findByStaffAndBook(Staff staff,Book book){
		try{
			return super.findByProperty("from Praise p where p.staff=? and p.book=?", new Object[]{staff,book});
		}catch(Exception e){
			e.printStackTrace();
			return null;
		}
	}

	public Praise getPraiseById(Integer praiseId){
		try{
			return super.get(praiseId);
		}catch(Exception e){
			e.printStackTrace();
			return null;
		}
	}


	public void savePraise(Praise praise){
		try {
			this.save(praise);
		} catch (Exception e) {
			e.printStackTrace();
		}
	}

	public void updatePraise(Praise praise){
		try {
			this.update(praise);
		} catch (Exception e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
	}

	public List<Praise> getAll(){
		try{
			return super.findByProperty("from Praise", new Object[]{});
		}catch(Exception e){
			e.printStackTrace();
			return null;
		}
	}

	public void deletePraise(Praise praise){
		try {
			this.delete(praise);
		} catch (Exception e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
	}
}
